const path = require('path'),
	config = require(path.join(__dirname, '../config.js')),
	jwt = require('jsonwebtoken'),
    md5 = require('md5')

async function main(event) {
	let body = event.body
	// console.log(typeof body , body, config.users[body.username])
	if (config.users[body.username] === body.password){
		const token = jwt.sign({
		        username:body.username,
				password:body.password
		    }, config.secret, {
		        expiresIn:  86400 //到期时间：单位秒 一天
		    })
		return {
			"code":200,
			"data":{
				"token":token
			},
			"msg":"success"
		}
	}else{
		return {
			"code":444,
			"data":{},
			"msg":"用户名或者密码错误"
		}
	}
}

module.exports = main